﻿Ext.define('TAB.view.user.UserNewOrEditForm', {
    extend: 'Ext.form.Panel',
    alias: 'widget.userNewOrEditForm',
    requires: [
        'BIM.store.Option',
        'Ext.ux.TreePicker'
    ],
    defaults: {
        xtype: 'textfield',
        labelWidth: 70,
        labelAlign: 'right',
        anchor: '95%'
    },
    bodyStyle: 'padding:5px 0px 5px 0px',
    items: [{
        xtype: 'hidden',
        name: 'FID',
        margin:0
    }, {
        name: 'FREALNAME',
        fieldLabel: '姓名',
        allowBlank: false,
        blankText: '姓名不能为空'
    }, {
        name: 'FNAME',
        fieldLabel: '用户名',
        allowBlank: false,
        blankText: '用户名不能为空',
        emptyText: '登录时用的用户名'
    }, /*{
        name: 'FPWD',
        fieldLabel: '密码',
        inputType: 'password',
        allowBlank: false,
        blankText: '密码不能为空'
    }, {
        name: 'FPWD2',
        fieldLabel: '重复密码',
        inputType: 'password',
        allowBlank: false,
        blankText: '密码不能为空'
    }, */
    {
        name: 'FJOBNUMBER',
        fieldLabel: '工号'
    }, {
        name: 'FSEX',
        fieldLabel: '性别',
        xtype: 'combo',
        multiSelect: false,
        forceSelection: true,
        queryMode: 'local',
        store: Ext.create('Ext.data.Store', {
            fields: ['value', 'text'],
            data: [{
                value: '男',
                text: '男'
            }, {
                value: '女',
                text: '女'
            }]
        }),
        queryMode: 'local',
        valueField: 'value',
        displayField: 'text',
        value: '男'
    }, {
        fieldLabel: '职务',
        xtype: 'combo',
        itemId: 'comboDuty',
        multiSelect: false,
        displayField: 'FNAME',
        valueField: 'FID',
        queryMode: 'local',
        typeAhead: true,
        forceSelection :true,
        listConfig:
        {
            loadMask: false
        },
        name: 'FDUTYID'
    }, {
        fieldLabel: '部门',
        xtype: 'treepicker',
        itemId: 'comboDept',
        name: 'FDEPARTMENTID',
        displayField: 'text',
        valueField: 'FID',
        listConfig:
        {
            loadMask: false
        },
        store: Ext.create('Ext.data.TreeStore', {
            fields: ['text', 'level', 'children','code'],
            root:
            {
                text: '组织结构'
            }
        })

    }, {
        name: 'FPHONENUMBER',
        xtype: 'numberfield',
        fieldLabel: '手机号'
    },{
        name: 'FTELNUMBER',
        fieldLabel: '固定电话'
    }, {
        name: 'FEMAIL',
        fieldLabel: '邮箱',
        vtype: 'email'
    },  {
        name: 'FBIRTHDAY',
        fieldLabel: '生日',
        xtype: 'datefield',
        format: 'Y-m-d',
        altFormats: 'Y-m-d',
        renderer: Ext.util.Format.dateRenderer('Y-m-d'),
        invalidText: '日期格式不对，格式形如：2013-05-03'
    }, {
        name: 'FISACTIVE',
        fieldLabel: '用户状态',
        xtype: 'combo',
        multiSelect: false,
        forceSelection: true,
        store: Ext.create('Ext.data.Store', {
            fields: ['value', 'text'],
            data: [{
                value: '1',
                text: '正常'
            }, {
                value: '0',
                text: '锁定'
            }]
        }),
        queryMode: 'local',
        valueField: 'value',
        displayField: 'text',
        value: '1'
    }, {
        name: 'FSORT',
        fieldLabel: '排序',
        xtype: 'numberfield',
        minValue: 1,
        emptyText: '不填则会智能生成'
    }, {
        xtype: 'textarea',
        name: 'FREMARK',
        fieldLabel: '备注'
    }],

    initComponent: function () {
        this.callParent(arguments);
        //职务
        var comboDuty = this.down('#comboDuty');
        comboDuty.store = Ext.create('BIM.store.Option', {
            autoLoad: true,
            proxy: {
                type: 'ajax',
                url: Twi.Url,
                reader: {
                    type: 'json',
                    root: 'data',
                    totalProperty: 'totalCount',
                    successProperty: 'success'
                },
                extraParams: {
                    cn: 'PageCommon',
                    mn: 'TAB',
                    mn2: 'GetBySimpleCondition',
                    data: Ext.encode({
                        TableName: 'SM004',
                        OrderFields: 'FSORT',
                        Condition:
                        {
                            FIsDeleted: 0,
                            FOptionTypeID: '846ca4f6-ae5c-4293-be47-332dd5604fc9'
                        }
                    })
                }
            }
        });

        //部门

        var comboDept = this.down('#comboDept');
        Twi.QuickAjax.Ajax({
            params: {
                cn: 'Tree',
                mn: 'TAB',
                mn2: 'GetTreeData',
                value: '1'
            },
            success: function (twi) {
                comboDept.store.setRootNode(twi.data[0]);
            }
        });
    }
});
